<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        window.onload=function(){
            var oTxt1=document.getElementById('txt1');
            var oTxt2=document.getElementById('txt2');
            var oBtn=document.getElementById('btn1');
            oBtn.onclick=function(){
                //alert(typeof oTxt1.value);//string
                var n1=parseInt(oTxt1.value);
                var n2=parseInt(oTxt2.value);
                //给一个判断，用户输入的内容是不是数字
                if(isNaN(n1)){
                    alert('您输入的第一个数字有误');
                }
               else if(isNaN(n2)){
                    alert('您输入的第二个数字有误');
                }
                else{
                   alert(n1+n2);
                }

              // alert(parseInt(oTxt1.value)+parseInt(oTxt2.value));
            };
        };


    </script>
</head>
<body>
<input type="text" id="txt1">
<input type="text" id="txt2">
<input type="button" id="btn1" value="求和">
</body>
</html>
<!--12+NaN=NaN-->